﻿using Lotus.AspNetCore.Client.Option;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lotus.AspNetCore.DI
{
    public static class BaseLutosServiceBaseCollectionExtensions
    {
        public static void AddBaseLutos(this IServiceCollection services, Action<BaseLutosOption> option)
        {
            if (services == null)
            {
                throw new ArgumentNullException("services");
            }

            services.Configure(option);


            services.AddSingleton<IBaseLotusClient, BaseLotusClient>((IServiceProvider s) =>
            {
                BaseLutosOption option = s.GetRequiredService<IOptions<BaseLutosOption>>().Value;

                if (string.IsNullOrEmpty(option.AppId) || string.IsNullOrEmpty(option.AppSecret))
                {
                    throw new ArgumentException("BaseLutosOption");
                }
                return new BaseLotusClient(option);
            });

            // var a = services.BuildServiceProvider().GetRequiredService<IOptions<BaseLogOption>>().Value;



        }
    }
}
